<?php
class Bootstrap_View extends Bootstrap_Abstarct{		
	const CACHE_VIEWREBDERER_NAME = 'class_viewRenderer';
	
	static public function build()	{	
		$config = Zend_Registry::get('config');			
		if(Zend_Registry::isRegistered('viewRenderer')){
			$viewRenderer = Zend_Registry::get('viewRenderer');
		}else{			
			$viewRenderer = self::loadCache(self::CACHE_VIEWREBDERER_NAME);
			if(!$viewRenderer instanceof Zend_Controller_Action_Helper_ViewRenderer){					
				$viewRenderer = new ControllerAction__Helper_ViewRenderer();				
				self::saveCache($viewRenderer, self::CACHE_VIEWREBDERER_NAME);
			}				
		}	
		if(empty($viewRenderer) or !$viewRenderer instanceof Zend_Controller_Action_Helper_ViewRenderer){
			throw new Exception("PLease check the view renderer settings.");
		}
		Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);		
		Zend_Registry::set('viewRenderer',$viewRenderer);

		//mvc
		if(!empty($config->view->layout)){
			$options['layoutPath'] = APP_DIR.DIRECTORY_SEPARATOR.trim($config->view->layout->path);	
			$options['layout'] = trim($config->view->layout->filename);	
			Zend_Layout::startMvc($options);
		}	
		return $viewRenderer;
	}
}